<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<title>修改兑换商品</title>
<%@include file="../collect/meta.jsp"%>
<style type="text/css">
.input {
	width: 180px;
	height: 25px;
	font-size: 14px
}

.tbinput {
	width: 180px;
	height: 25px;
	font-size: 14px;
	background-color: #FFFFCC
}

.error {
	color: red
}

.success {
	color: green
}
</style>
<link rel="stylesheet" href="css/radius.css" type="text/css"></link>
<script type="text/javascript" src="${ctx}/js/returnTop.js"></script>
</head>
<body lang="zh-cn">
	<div class="wrapper">
		<c:import url="/collect/top.jsp"></c:import>
		<div class="main-container" id="main-container">
			<div class="main-container-inner">
				<c:import url="/collect/left.jsp"></c:import>
				<div class="main-content">
					<div class="breadcrumbs" id="breadcrumbs">
						<ul class="breadcrumb">
							<li><i class="icon-home home-icon"></i>商品兑换</li>
							<li><a href="exchangegood!watchExgoods">兑换管理</a>
							</li>
							<li>修改兑换商品</li>
						</ul>
					</div>
					<div class="page-content">
						<div class="page-content-area">
							<div class="page-header">
								<h1>商品信息</h1>
							</div>
							<div class="row">
								<div class="col-xs-12">
									<form class="form-horizontal" name="modifyExchangeGoods"
										action="exchangegood!modifyExgood" method="post">
										<input type="hidden" id="eaId" name="exchangeGood.eaId"
											value="${exchangeGood.eaId }"> <input type="hidden"
											id="exgoodId" name="exchangeGood.id"
											value="${exchangeGood.id }">
										<div id="table_bug_report">
											<div class="form-group">
												<label for="goodname" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp商品名称:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="exchangeGood.goodname"
														id="goodname" value="${exchangeGood.goodname }">
												</div>
											</div>
											<div class="form-group">
												<label class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp店铺名称:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<select class="form-control" id="shopId"
														name="exchangeGood.shopId"
														style="width: 200px;">
														<c:forEach items="${shops}" var="shop">
															<option value="${shop.id }"
																<c:if test="${shop.id == exchangeGood.shopId }">selected="selected"</c:if>>${shop.name}
															</option>
														</c:forEach>
													</select>
												</div>
											</div>
											<div class="form-group">
												<label for="score" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp兑换积分:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="iscore" id="score"
														value="${exchangeGood.score }">
												</div>
											</div>
											<div class="form-group">
												<label for="amount" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp商品数量:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="exchangeGood.amount"
														id="amount" value="${exchangeGood.amount }">
												</div>
											</div>
											<div class="form-group">
												<label for="exchangeAmount" class="col-xs-2 col-sm-1 col-md-2"
													style="width:100px;">&nbsp兑换次数:</label>
												<div class="col-xs-9 col-sm-6 col-md-10">
													<input type="text" class="form-control"
														style="width:200px;" name="exchangeGood.exchangeAmount"
														id="exchangeAmount" value="${exchangeGood.exchangeAmount }">
													<p style="font-weight:bold;color:#0096BB;position:absolute;margin-left:210px;margin-top:-18px;">
														(兑换次数是指每个会员可兑换该商品的次数,不填写或填写0代表可无限次兑换)
													</p>
												</div>
											</div>
											<div class="clearfix">
												<div style="padding-left:100px;">
													<button class="btn btn-primary radius" type="button"
														onclick="sub();">确定</button>
													&nbsp;<a class="btn btn-primary radius"
														href="exchangegood!watchExgoods">返回</a>
												</div>
											</div>
										</div>
									</form>
								</div>
							</div>
							<!-- /.row -->
						</div>
						<!-- /.page-content-area -->
					</div>
					<!-- /.page-content-content -->
				</div>
			</div>
			<a href="#" id="btn-scroll-up"
				class="btn-scroll-up btn btn-sm btn-inverse"
				style="position:fixed;bottom:0;"> <i
				class="icon-double-angle-up icon-only bigger-110"></i> </a>
		</div>
		<div class="push"></div>
	</div>
	<c:import url="/collect/down.jsp"></c:import>
	<script type="text/javascript">
		$(function() {
			var score = document.getElementById("score").value;
			var index = score.indexOf(".0");
			if (index != -1) {
				score = score.substring(0, index);
			}
			$("#score").val(score);
			if($("#exchangeAmount").val() == 0) {
				$("#exchangeAmount").val("");
			};
		});

		function sub() {
			var goodname = document.getElementById("goodname").value;
			var score = document.getElementById("score").value;
			var amount = document.getElementById("amount").value;

			var flag = true;

			if (goodname.length == 0) {
				alert("请输入商品名称！");
				return false;
			}

			if (score.length == 0) {
				alert("请输入兑换积分！");
				return false;
			}
			if (!/^\d+$/.test(score)) {
				alert("兑换积分必须是正整数！");
				return false;
			}

			if (amount.length == 0) {
				alert("请输入商品数量！");
				return false;
			}
			if (!/^\d+$/.test(amount)) {
				alert("商品数量必须是正整数！");
				return false;
			}

			var eaId = $("#eaId").val();
			var shopId = $("#shopId").val();
			var exgoodId = $("#exgoodId").val();
			$.ajax({
				async : false,
				url : "exchangegood!verifyGoodnameById",
				type : "post",
				data : {
					"goodname" : goodname,
					"eaId" : eaId,
					"shopId" : shopId,
					"exgoodId" : exgoodId
				},
				datatype : "json",
				success : function(data) {
					var map = eval("(" + data + ")");
					if (map != null) {
						flag = false;
						alert(map.temp);
					}
				},
				error : function(request) {
					flag = false;
					alert("Connection error");
				}
			});

			if (!/^\d+$/.test($("#exchangeAmount").val())) {
				$("#exchangeAmount").val("");
			}
			
			if (flag) {
				modifyExchangeGoods.submit();
			}
		}
		$('.goodsexchange > ul').show();
		$('.goodsexchange > ul > li > a').eq(0).css("color", "red");
	</script>
</body>
</html>